﻿using System.Reflection;
using NHibernate;
using NHibernate.Cfg;

namespace Golf.DataLayer
{
    public abstract class RepositoryBase
    {
        protected RepositoryBase()
        {
            _config = CreateConfig();
            _sessionFactory = _config.BuildSessionFactory();
        }

        private Configuration _config;
        protected Configuration Config
        {
            get { return _config; }
        }

        private ISessionFactory _sessionFactory;
        protected ISessionFactory SessionFactory
        {
            get { return _sessionFactory; }
        }

        private Configuration CreateConfig()
        {
            Configuration config = new Configuration();
            config.Configure();
            config.AddAssembly(Assembly.GetExecutingAssembly());
            return config;
        }
    }
}